<!DOCTYPE HTML>
<html>
<head>
<include file="public/header" />
<style>
	.table{
		margin-left:14% !important;
		width:84% !important;
	}
	.table tr td{
		text-align:left !important;
	}
	.table tr td:first-child,.table tr td:last-child{
		text-align:center !important;
	}
	tbody tr:hover{
		background:#f1f1f1;
	}
</style>
<title>添加角色</title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add">
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="{$role.title}" placeholder="请填写角色名称" id="name" name="name">
		</div>
	</div>
	
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否启用：</label>
		<div class="formControls col-xs-8 col-sm-9 skin-minimal">
			<div class="radio-box">
				<input value="1" name="status" type="radio" id="status-1" checked>
				<label for="status-1">启用</label>
			</div>
			<div class="radio-box">
				<input value="0" name="status" type="radio" <if condition="$role['status'] === 0">checked</if> id="status-2">
				<label for="status-2">禁用</label>
			</div>
		</div>
	</div>
	<div class="row cl">
		<table class="table table-border table-bordered table-bg">
			<thead>
				<tr>
					<th scope="col" colspan="7">权限节点</th>
				</tr>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th>权限名称</th>
					<th width="200">权限状态</th>
				</tr>
			</thead>
			<tbody>
				<volist name="permission" id="v">
					<tr class="text-c">
						<td><input <if condition="in_array($v['id'],$ruleid)">checked</if> type="checkbox" name="ruleid[]" value-name="{$v.name}" value="{$v.id}"></td>
						<td>{$v.title}</td>
						<td><if condition='$v["status"] eq 1'><span style='color:green;'>已启用</span><else/><span style='color:red;'>已停用</span></if></td>
					</tr>
					<if condition="isset($v['list'])">
						<volist name="$v.list" id="v2">
							<tr class="text-c">
								<td><input <if condition="in_array($v2['id'],$ruleid)">checked</if> name="ruleid[]" value-name="{$v2.name}" type="checkbox" value="{$v2.id}"></td>
								<td><span style='padding:0 15px;'>&nbsp;</span><img src="__STATIC__/image/line.png" /> {$v2.title}</td>
								<td><if condition='$v2["status"] eq 1'><span style='color:green;'>已启用</span><else/><span style='color:red;'>已停用</span></if></td>
							</tr>
							<if condition="isset($v2['list'])">
								<volist name="$v2.list" id="v3">
									<tr class="text-c">
										<td><input <if condition="in_array($v3['id'],$ruleid)">checked</if> name="ruleid[]" value-name="{$v3.name}" type="checkbox" value="{$v3.id}"></td>
										<td><span style='padding:0 30px;'>&nbsp;</span><img src="__STATIC__/image/line.png" /> {$v3.title}</td>
										<td><if condition='$v3["status"] eq 1'><span style='color:green;'>已启用</span><else/><span style='color:red;'>已停用</span></if></td>
									</tr>
								</volist>
							</if>
						</volist>
					</if>
				</volist>
			</tbody>
		</table>
	</div>
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
		</div>
	</div>
	<input type="hidden" name="id" value="{$id}" />
	</form>
</article>

<include file="public/footer" />

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script> 
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-admin-add").validate({
		rules:{
			name:{
				required:true,
			}
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				type: 'post',
				url: "{:url('User/addrole')}" ,
				success: function(data){
					if(data.error=="success"){
						layer.msg('操作成功!',{icon:6,time:1000});
						setTimeout(function(){
							parent.location.replace(parent.location.href)
						},1500);
					}else{
						layer.msg(data.error,{icon:5,time:1000});
					}
				},
                error: function(err){
					layer.msg('操作失败！',{icon:5,time:1000});
				}
			});
		}
	});
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
<script src="__STATIC__/js/auth.js"></script>
</body>
</html>